/* 
 * Copyright (C), 2016-2020, 厦门盈欣宝金融信息服务有限公司
 * Project Name :boot-parent
 * File Name: org.easytouseit.bootservlet.interceptor
 * Encoding UTF-8 
 * Version: 1.0 
 * Date: 2018-07-31 16:55
 * History:  
 * 1. Date: 2018-07-31
 *    Author: guojm 
 *    Modification: 新建
 * 2. ...
 */
package org.easytouseit.bootservlet.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器
 *
 * @author guojm
 * @version V1.0
 * @date 2018-07-31
 */
@Slf4j
public class CustomMyInterceptor2 implements HandlerInterceptor{

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("CustomMyInterceptor2==========>在请求处理之前进行调用（Controller方法调用之前）");
       return true;// 只有返回true才会继续向下执行，返回false取消当前请求

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        log.info("请求处理之后进行调用，但是在视图被渲染之前（Controller方法调用之后）2");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        log.info("在整个请求结束之后被调用，也就是在DispatcherServlet渲染了对应的视图之后执行（主要是用于进行资源清理工作）2");
    }
}
